package com.qf.servlet;

import com.qf.entity.Book;
import com.qf.service.BookService;
import com.qf.service.impl.BookServiceImpl;
import com.qf.util.MyUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author 孙亚梅
 * @version V1.0
 * @Project bookApp-homework
 * @Package ${PACKAGE_NAME}
 * @Description: ${TODO}
 * @Date 2022/5/15 11:50
 */
@WebServlet(name = "UpdateServlet",urlPatterns = "/updateBook")
public class UpdateServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");

//        HttpSession session = request.getSession();

        //获取参数
        Integer bookId = Integer.parseInt(request.getParameter("bookId"));
        String name = request.getParameter("name");
        String author = request.getParameter("author");
        double price = Double.parseDouble(request.getParameter("price"));
        String description = request.getParameter("description");
        String publisher = request.getParameter("publisher");

        Book book = new Book(bookId, name, price, description, author, publisher);

        BookService bookService = new BookServiceImpl();

        bookService.updateBook(book);
        response.sendRedirect(request.getContextPath() + "/bookList");
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
